package com.leave.mos.controller;

import com.leave.mos.entity.User;
import com.leave.mos.service.MongodbService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @ClassName MongodbController
 * @Description TODO
 * @Author lh
 * @Date 2021/7/6 14:50
 * @Version 1.0
 **/
@RestController
@RequestMapping("mongodb")
public class MongodbController {

    @Autowired
    private MongodbService mongodbService;

    @GetMapping("findOneUser")
    public String findOneUser(String username){
        User user = mongodbService.findOneUser(username);
        return user.toString();
    }

    @PostMapping("saveUser")
    public String saveUser(User user){

        mongodbService.saveUser(user);
        return "success";
    }

    @PostMapping("updateUser")
    public long updateUser(User user){

        long l = mongodbService.updateUser(user);
        return l;
    }

    @PostMapping("removeUserById")
    public String removeUserById(String id){

        mongodbService.removeUserById(id);
        return "del success";
    }

}
